# ===============================================================#
#                          设置基站周围覆盖值
# 参数：1.option ：为1表示智能体覆盖，为2表示基站覆盖、
#      2.edge_value ：表示边缘覆盖值
#      3.in_value : 表示内部覆盖值
# ===============================================================#
import math

import numpy

def coverage_value(mx,my,r,C,option,in_value,edge_value):
    # 根据半径设置覆盖值
    xl = numpy.linspace(0,len(C)-1,len(C))
    re = numpy.square(xl - mx) + numpy.square(xl - my)
    D = numpy.argwhere(re <= (r+1)**2)  # D 为n行两列

    for i in range(len(D)):
        # 智能体覆盖
        if option == 1 and (C[D[i,1],D[i,2]] == 0 or C[D[i,1],D[i,2]] == edge_value):
            d = math.sqrt((D[i,1]-mx-1)**2 + (D[i,2]-my-1)**2)
            if d > r:  # 智能体边缘处
                C(D[i,1],D[i,2]) == edge_value
            else:
                C(D[i, 1], D[i, 2]) == in_value
        # 基站覆盖区域赋值
        if option == 2 and (C[D[i, 1], D[i, 2]] == 0 or C[D[i, 1], D[i, 2]] == edge_value):
            d = math.sqrt((D[i, 1] - mx - 1) ** 2 + (D[i, 2] - my - 1) ** 2)
            if d > r:  # 智能体边缘处
                C(D[i, 1], D[i, 2]) == edge_value
            else:
                C(D[i, 1], D[i, 2]) == in_value

    return C